import { AlovaInstance } from '@/utils/http/alova';

export interface Wireless {
  bandwidth: string; // 传输带宽
  firmware: string; // 固件版本信息
  frqLck: string; // 锁频
  lcaddress: string; // 无线模块地址
  lcdbm: string; // 发射功率
  lcghz: string; // 频段信息
  pass: string;
  pwd: string; // 配对秘钥
  rsnode: string; // 无线模块工作模式
  updown: string; // 上下行分配
  user: string;
}

export interface Sender {
  dist: number;
  ipAddr?: string;
  mastSlav?: number;
  rsrp: number;
  rsrq: number;
  rssi: number;
  ser: number;
  snr: number;
  snr_max: number;
  snr_min: number;
  earfcn?: number;
  tx_power?: number;
}

export interface LogMessage {
  errorCode: number;
  errorMsg: string;
  id: number;
  jsonrpc: string;
  result: string;
  senders: Sender[];
}

/**
 * 获取无线参数
 */
export function getWireless(): Promise<Wireless> {
  return AlovaInstance.Post('', {
    method: 'get',
    lc6600list:
      'attr,lcid,lcpid,pwd,lcaddress,rsnode,lcdbm,lcghz,updown,lcmin,bandwidth,freqbandwidthauto,firmware,user,pass',
  });
}

/**
 * 设置无线参数
 */
export function setWireless(config: string) {
  return AlovaInstance.Post('', {
    method: 'set',
    lc6600list: config,
  });
}

/**
 * 获取日志信息
 */
export function getlog(): Promise<LogMessage> {
  return AlovaInstance.Post('', {
    method: 'get',
    radio_req: '',
  });
}

export function getSenderLog(): Promise<LogMessage> {
  return AlovaInstance.Post('', {
    method: 'get',
    sender_radio_req: '',
  });
}

/**
 * 重启设备
 */
export function restart() {
  return AlovaInstance.Post('', {
    method: 'set',
    reset: 0,
  });
}
